package com.example.controller;

import com.example.model.dto.CreateShopDTO;
import com.example.model.dto.Result;
import com.example.service.IShopService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @program: backend
 * @author: zk
 * @create: 2023-04-21 16:23
 **/

@Slf4j
@RestController
@RequestMapping("/products")
@Api(tags = "商品信息")
public class ShopController {
    @Resource
    private IShopService productsService;

    /**
     * 根据页号和数量获取商品
     *
     * @param pageNum
     * @param pageSize
     * @return
     */
    @ApiOperation("根据页号和数量获取商品")
    @GetMapping
    public Result getShops(@RequestParam int pageNum, @RequestParam int pageSize) {
        return productsService.getShops(pageNum, pageSize);
    }

    /**
     * 更具商品id获取商品信息
     *
     * @param productId
     * @return
     */
    @ApiOperation("更具商品id获取商品信息")
    @GetMapping("{productId}")
    public Result getShop(@PathVariable("productId") String productId) {
        return productsService.getShop(productId);
    }

    @ApiOperation("保存商品信息")
    @PostMapping()
    public Result getShop(@RequestBody CreateShopDTO shop) {
        return productsService.saveShoeShop(shop);
    }


}
